package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.ClientBean;
import com.project.mapper.IClientMapper;
import com.project.service.IClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
/**
 * @Title: ClientServiceImpl
 * @Package: com.project.service.impl
 * @Description:
 * @Author: Liang-Xie
 */
@SuppressWarnings("all")
@Service
@Transactional
public class ClientServiceImpl implements IClientService {

    @Autowired
    private IClientMapper clientMapper;

    @Override
    public IPage<ClientBean> findByItem(Integer pageNO, String name, String scope) {
        QueryWrapper<ClientBean> qw = new QueryWrapper<>();
        if (name != null && name.length() != 0){
            qw.like("c_name",name);
        }
        if (scope != null && scope.length() !=0){
            qw.like("c_scope",scope);
        }
        return clientMapper.selectPage(new Page<>(pageNO,3),qw);
    }

    @Override
    public ClientBean findById(Integer clientId) {
        return clientMapper.selectById(clientId);
    }

    @Override
    public void update(Integer clientId, String person, String phone, String scope) {
        ClientBean client = new ClientBean();
        client.setId(clientId);
        client.setUser(person);
        client.setPhone(phone);
        client.setScope(scope);
        clientMapper.updateById(client);
    }

    @Override
    public void add(ClientBean client) {
        clientMapper.insert(client);
    }

    @Override
    public List<ClientBean> findAll() {
        return clientMapper.selectList(null);
    }
}
